package com.ccsu.eb.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ccsu.eb.service.EbProductCategoryService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

/**
 * @Description: 用一句话描述
 * @Auther: 新梦想*陈超
 * @Date: 2022/3/18 11:11
 */
@Controller
@RequestMapping("/category")
public class EbProductCategoryController {

    @Resource
    private EbProductCategoryService  ebProductCategoryService;
    @RequestMapping("/linked_product")
    public String linkedProduct(Model model, Integer cateId,
                                @RequestParam(value = "pnum",defaultValue = "1") Integer pnum){
        System.out.println("进入EbProductController的detail方法，cateId=="+cateId);
        //TODO 1.调用service根据ID获取商品
        Page productPage = ebProductCategoryService.findProductListByCateId(cateId, pnum,false);
        //TODO 2.绑定到model---数据
        model.addAttribute("productPage",productPage);
        //TODO  3.返回view--html
        return "product-list";//templates/product-list.html
    }

    /**
         *  根据商品的 一级分类id查询商品列表
     * @param model     model渲染的模型 数据
     * @param bigCateId 一级分类id(大类id)
     * @param pnum      页数
     * @return
     */
    @RequestMapping("/linked_big_cate")
    public String linkedBigCateProduct(Model model,Integer bigCateId,
                                       @RequestParam(value = "pnum",defaultValue = "1") Integer pnum){
        //TODO 1.调用service根据ID获取商品
        Page productPage = ebProductCategoryService.findProductListByCateId(bigCateId, pnum,true);
        //TODO 2.绑定到model---数据
        model.addAttribute("productPage",productPage);
        //TODO  3.返回view--html
        return "product-list";//templates/product-list.html
    }
}
